import {JavaJUnitParser} from './parsers/java-junit/java-junit-parser'
import {MochaParser} from './parsers/node/mocha-parser'
import {GolangTestParser} from './parsers/golang-test/golang-test-parser'
import {PytestParser} from './parsers/python-pytest/pytest-parser'
import {PhpUnitTestParser} from './parsers/php-unit-test/php-unit-test-parser'

export type Coverage = {
  total: number,
  passed: number,
  failed: number,
  skipped: number,
  passedRate: number
}

export interface TestParser {
  coverageFile(path: string): Promise<string>

  parse(path: string): Promise<Coverage>

  htmlFile(path: string): string
}

export function getParser(reporter: string): TestParser {
  switch (reporter) {
    case 'Java-JUnit':
      return new JavaJUnitParser()
    case 'Node.js-Mocha':
      return new MochaParser()
    case 'Golang-Test':
      return new GolangTestParser()
    case 'Python-Pytest':
      return new PytestParser()
    case 'Php-UnitTest':
      return new PhpUnitTestParser()
    default:
      throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`)
  }
}